// Turn-Based Engine
// Do Player and State 1-based for display purpose - 0 is an error

#include <stdlib.h>
#include <assert.h>

#include "GameRuleEngine.h"

CGameRuleEngine::CGameRuleEngine(int PlayerCount, int PlayerStart, bool RandomPlayerStart, int StateCount) : 
	m_PlayerCount(PlayerCount),
	m_StateCount(StateCount)
{
	if (RandomPlayerStart)
	{
		m_CurrentPlayer = (rand() % m_PlayerCount) + 1;
	}
	else
	{
		m_CurrentPlayer = 1;
	}
	
	m_CurrentState = 1;
}
		
void CGameRuleEngine::NextPlayer()
{
	m_CurrentPlayer++;
	if (m_CurrentPlayer > m_PlayerCount)
	{
		m_CurrentPlayer = 1;
	}
}

void CGameRuleEngine::NextState()
{
	m_CurrentState++;
	if (m_CurrentState > m_StateCount)
	{
		m_CurrentState = 1;
	}
}

void CGameRuleEngine::SetState(int State)
{
	m_CurrentState = State;
	
	// check state
	if (m_CurrentState > m_StateCount)
	{
		m_CurrentState = 1;
	}
	
	// bring back to initial state
	if (m_CurrentState < 1)
	{
		m_CurrentState = 0;
	}
}
